﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;

public partial class LoginService : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session.Clear();
        string username = Request.QueryString["X"];
        string pwd = Request.QueryString["Y"];
        string connectkey = System.Configuration.ConfigurationManager.AppSettings["connectkey"];

        if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(pwd) || string.IsNullOrEmpty(connectkey))
        {
            Response.End();
            return;
        }
        else
        {
            HZ.SinglePointLogin.RedirectHelper rh = new HZ.SinglePointLogin.RedirectHelper();
            try
            {
                username = rh.DecryptUrlString(username, connectkey);
                pwd = rh.DecryptUrlString(pwd, connectkey);

                User account;//= CurrentAccount.GetUser();

                var r = HZ.Supervise.BLLFactory.BLL_Login().SinglePointLogin(username, pwd, out  account);

                if (r == 1)
                {

                    if ((account.IsUsing == false))
                    {
                        HZ.Web.WebUtil.Alert("该用户禁用在此系统");
                        Response.End();
                    }

                    // 记录info级别日志
                    HZ.Common.log4netManager.LogInfo("单点登录系统", string.Format("登录成功:登录用户编号{0},登录IP地址{1}", account.UserName, HZ.Fun.GetClientIP()), null);

                    if (account.UserRole.RoleID == "04" || account.UserRole.RoleID == "03")
                    {
                        CurrentAccount.SetUser(account);
                        string str = "parent.location='PageControl/Center.aspx'";
                        Response.Write(HZ.Web.WebUtil.GetScript(str));
                    }
                    else
                    {
                        HZ.Web.WebUtil.Alert("禁止该类型账户登录系统！");
                        return;
                    }
                }
                else
                {
                    HZ.Web.WebUtil.Alert("不存在该用户");
                }


            }
            catch (Exception ee)
            {

                HZ.Common.log4netManager.LogWarn("非法进入", string.Format("系统发现非法单点登录记录\r\n登录IP地址：{0}.\r\n登录串:{1}", HZ.Fun.GetClientIP(), username), ee);
                Response.End();
                return;
            }


        }
    }
}
